﻿// (c) Comkarl Calipso
// By Matías Fidemraizer (http://www.matiasfidemraizer.com)
// -------------------------------------------------
// http://calipso.codeplex.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.



namespace Comkarl.Web.Serialization
{
    /// <summary>
    /// Represents a JSON serializer.
    /// </summary>
    public abstract class JsonSerializer
    {
        /// <summary>
        /// Gets current JSON serializer implementation.
        /// </summary>
        public static JsonSerializer Current
        {
            get
            {
                return Component.Resolve<JsonSerializer>("JsonSerializer");
            }
        }

        /// <summary>
        /// In derived classes, serializes some object and returns a JSON string.
        /// </summary>
        /// <param name="some">
        /// The whole object to serialize.
        /// </param>
        /// <returns>
        /// The JSON string of given serialized object.
        /// </returns>
        public abstract string Serialize(object some);

        /// <summary>
        /// In derived classes, deserializes a given object as JSON string.
        /// </summary>
        /// <param name="text">
        /// The whole JSON string-
        /// </param>
        /// <returns>
        /// An object.
        /// </returns>
        public abstract object Deserialize(string text);

        /// <summary>
        /// In derived classes, gets an array of JSON object properties.
        /// </summary>
        /// <param name="text">
        /// The JSON object string.
        /// </param>
        /// <returns>
        /// An array of property names.
        /// </returns>
        public abstract string[] DeserializePropertyNames(string text);

        /// <summary>
        /// In derived classes, deserializes a given object as JSON string-
        /// </summary>
        /// <typeparam name="TDeserializedObject">
        /// The type of JSON object.
        /// </typeparam>
        /// <param name="text">
        /// The whole JSON string to deserialize.
        /// </param>
        /// <returns>
        /// A typed object.
        /// </returns>
        public abstract TDeserializedObject Deserialize<TDeserializedObject>(string text);
    }
}